﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.BLL;
using System.Drawing.Printing;

namespace WHC.Hotel.UI.Controls
{
    public partial class FrmPrintOptions : Form
    {
        public PrintableListView listView = null;

        public FrmPrintOptions()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            listView.Title = txtTitle.Text;
            listView.FitToPage = chkFitToPageWidth.Checked;
            listView.BottomTitle = txtBottom.Text;
            listView.PrintDoc.DefaultPageSettings.Landscape = radHorizontal.Checked;
            listView.PrintPreview();
        }

        private void btnPrintSetting_Click(object sender, EventArgs e)
        {
            if (listView != null)
            {
                if (listView.PageSetup() == DialogResult.OK)
                {
                    bool landscape = listView.PrintDoc.DefaultPageSettings.Landscape;
                    this.radHorizontal.Checked = landscape;
                    this.radVertical.Checked = !landscape;
                    SystemConfig.Default.ReportPrinterLandscape = landscape;
                    SystemConfig.Default.Save();
                }
            }
        }

        private void FrmPrintOptions_Load(object sender, EventArgs e)
        {
            if (listView != null)
            {
                //int leftMargin = SystemConfig.Default.ReportPrinterLeftMargin;
                //int topMargin = SystemConfig.Default.ReportPrinterTopMargin;
                //listView.PrintDoc.DefaultPageSettings.Margins = new Margins(leftMargin, leftMargin, topMargin, topMargin);
                listView.PrintDoc.PrinterSettings.PrinterName = SystemConfig.Default.ReportPrinterName;
                listView.PrintDoc.DefaultPageSettings.Landscape = SystemConfig.Default.ReportPrinterLandscape;
                this.radHorizontal.Checked = SystemConfig.Default.ReportPrinterLandscape;
                this.radVertical.Checked = !SystemConfig.Default.ReportPrinterLandscape;
            }
        }

        private void radVertical_CheckedChanged(object sender, EventArgs e)
        {
            listView.PrintDoc.DefaultPageSettings.Landscape = radHorizontal.Checked;
            SystemConfig.Default.ReportPrinterLandscape = radHorizontal.Checked;
            SystemConfig.Default.Save();
        }

        private void radHorizontal_CheckedChanged(object sender, EventArgs e)
        {
            listView.PrintDoc.DefaultPageSettings.Landscape = radHorizontal.Checked;
            SystemConfig.Default.ReportPrinterLandscape = radHorizontal.Checked;
            SystemConfig.Default.Save();
        }
    }
}
